//contact template: {$TEMPLATE} {literal}
var KONFIGURATOR_BEZUGSTOFFE_2 = {};
$.extend(KONFIGURATOR_BEZUGSTOFFE_2, KONFIGURATOR_BASE_BEZUGSTOFFE, {

	praefix: 'bezugstoffe_2',
	description: 'Bezugsstoff zweifarbig',
	value: {front: '', rear: ''},

  loadValue: function(id) {
		var ids = id.split('|');
  	var imgId = $('#gallery_bezugstoffe_front_thmb_'+ids[0]).parents('div.thmb');
  	this.onChooseThmb({currentTarget: imgId.get(0)});
  	imgId = $('#gallery_bezugstoffe_rear_thmb_'+ids[1]).parents('div.thmb');
  	this.onChooseThmb({currentTarget: imgId.get(0)});
{/literal}{if $FORM_ACTION == true}{literal}
  	this.onChange();
  },

  onChange: function() {
  	var img_folder = 'BEZUGSTOFFE';
  	var praefix_upper = this.praefix.toUpperCase();
  	var cls = this;
 
		$.each(['front', 'rear'], function(k, v) { 
			choose = v;
			if (v=='rear' && $('#gallery_'+cls.praefix+' span[name=equal-front] input').get(0).checked) {
				choose='front';
		  	$('#gallery_'+cls.praefix+' div.selected[rel=rear] span[name=name-select]').html(
		  		$('#gallery_'+cls.praefix+' div.selected[rel=front] span[name=name-select]').html()
		  	);
		  }

			$('#gallery_'+cls.praefix+' div.selected[rel='+choose+'] div[name=id-select]').html();
			cls.value[v] = $('#gallery_'+cls.praefix+' div.selected[rel='+choose+'] div[name=id-select]').html();
			var img_name = $('#gallery_'+cls.praefix+' div.selected[rel='+choose+'] div[name=src-select]').html();

			$('#thmb_'+praefix_upper+'_'+v+' a').attr({'href': window.KONFIGURATOR_IMGPATH_POPUP+img_folder+'/'+img_name});
			$('#thmb_'+praefix_upper+'_'+v+' img').attr({'src': window.KONFIGURATOR_IMGPATH_THMB+img_folder+'/'+img_name});
			$('#thmb_'+praefix_upper+'_'+v).show();
		})
  	
		$('.container_popup_layer .btn_close').click();
  	$('#'+praefix_upper).val(this.value['front'] + '|' + this.value['rear']);
  	$('#'+praefix_upper).change();
  	
  	$('div[tmpl='+praefix_upper+'] span.name_option').html(
  		$('#gallery_'+this.praefix+' div.selected[rel=front] span[name=name-select]').html()
  		+ '/ ' + $('#gallery_'+this.praefix+' div.selected[rel=rear] span[name=name-select]').html()
  	);
  	
  },
  
	enableEqualRear: function(hasIt) {
		if(hasIt)
	  	$('#gallery_'+this.praefix+' span[name=equal-front]').show();
	  else {
	  	$('#gallery_'+this.praefix+' span[name=equal-front] input').get(0).checked = false;
			$('#gallery_'+this.praefix+' span[name=equal-front]').hide()  	
	  	this.setEqualRear();
	  }
	},

	setEqualRear: function() {
		var target = $('#gallery_'+this.praefix+' span[name=equal-front] input').get(0);
		if (target.checked)	{
			$('#gallery_'+this.praefix+' div[rel="bezug-tabs"]').tabs('option', 'active', 0);
			$('#gallery_'+this.praefix+' div[rel="bezug-tabs"]').tabs('disable', 1);
			$('#gallery_'+this.praefix+' div.selected[rel=rear] span[name=cnt-select]').hide();
		}
		else {
			$('#gallery_'+this.praefix+' div[rel="bezug-tabs"]').tabs('enable', 1);
			$('#gallery_'+this.praefix+' div.selected[rel=rear] span[name=cnt-select]').show();
		}
	}

{/literal}{else}{literal}
  }
{/literal}{/if}{literal}
	
});


$(document).ready(function() { 
	$D('init start ..');
	KONFIGURATOR_BEZUGSTOFFE_2.init(); 
	$D('init success ..');
	$(document).trigger('konfigurator_load', 'KONFIGURATOR_BEZUGSTOFFE_2');
});

{/literal}




